package com.geek.gkfgw.web.controller.meal.book;

import com.geek.gkdoc.facade.DocMethod;
import com.geek.gkfgw.facade.abs.Response;
import com.geek.gkfgw.facade.meal.book.SnatchOrderRequest;
import com.geek.gkfgw.facade.meal.book.SnatchOrderResponse;
import com.geek.gkfgw.integration.gkfood.MealBookFacadeClient;
import com.geek.gkfgw.integration.gkfood.bean.SnatchOrderReqBean;
import com.geek.gkfgw.integration.gkfood.bean.SnatchOrderRespBean;
import com.geek.gkfgw.util.json.JacksonUtils;
import com.geek.gkfgw.web.model.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <h1>餐饮预定控制器。</h1><br/>
 *
 * <h1><br/><a href="https://u.geekbang.org/subject/arch3/100614201">Java 业务架构实战营：https://u.geekbang.org/subject/arch3/100614201</a></h1><br/><h1><a href="https://gitee.com/ylimhhmily/BizArchPracticeCamp">Java 业务架构实战营代码地址：https://gitee.com/ylimhhmily/BizArchPracticeCamp</a></h1><br/><h1><a href="https://u.geekbang.org/subject/java4th/1001148?source=app_share">高级 Java 工程体系课 2023 版：https://u.geekbang.org/subject/java4th/1001148?source=app_share</a></h1><br/><h1><a href="https://time.geekbang.org/column/intro/100312101?tab=catalog">Dubbo 源码剖析与实战：https://time.geekbang.org/column/intro/100312101?tab=catalog</a></h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2023/9/23 16:08
 */
@RestController
public class MealBookController {

    @Autowired
    private MealBookFacadeClient mealBookFacadeClient;

    @DocMethod(desc = "餐饮抢单下单", author = "hmilyylimh", version = "20230915")
    @PostMapping("/gkfgw/meal/book/snatchOrder.json")
    public Response<SnatchOrderResponse> snatchOrder(@RequestBody SnatchOrderRequest req) {
        // 请求调用
        SnatchOrderReqBean reqBean = JacksonUtils.fromJson(JacksonUtils.toJson(req), SnatchOrderReqBean.class);
        SnatchOrderRespBean respBean = mealBookFacadeClient.snatchOrder(reqBean);

        // 解析响应
        SnatchOrderResponse response = JacksonUtils.fromJson(JacksonUtils.toJson(respBean), SnatchOrderResponse.class);
        return BaseResponse.ok(response);
    }
}